﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BizBrowser.RPT
{
    public class Printer
    {
        
        string baseDir = Path.Combine(Application.StartupPath, "reports");
        private string tempName = "";
        public FastReport.Report report = new FastReport.Report();
        public Printer(String fileName)
        {
            this.tempName = fileName;
        }

        public void RegisterData(IEnumerable data, String name)
        {
            report.RegisterData(data, name);
        }
        /// <summary>
        /// 直接打印报表工具
        /// 传入打印机名称
        /// 打印完成后保存打印模板与打印机对应关系用于第二次默认选中打印机
        /// 
        /// </summary>
        /// <param name="printName"></param>
        /// <returns></returns>
        public String PrintReprot(String printName)
        {
            try
            {
                var reportFile = Path.Combine(baseDir, tempName);
                report.Load(reportFile);
                report.PrintSettings.Printer = printName;
                report.PrintSettings.ShowDialog = false;
                report.PrintPrepared();
                report.Print();
                PrintUtil.SetValue(tempName, printName);

            }catch(Exception e)
            {
                return e.ToString() ;
            }
            return "1";
        }

    }
}
